home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / fmodla13.zip / LONGJUMP.DEF < prev    next >
Text File  |  1992-01-29  |  2KB  |  56 lines

  1. DEFINITION MODULE LongJump;
  2.  
  3. (* (C) Copyright 1987 Fitted Software Tools. All rights reserved. *)
  4.  
  5. (*
  6.     SetJump saves the current execution environment in the passed
  7.     parameter, and returns 0.
  8.  
  9.     LongJump restores the environment saved by a prior SetJump;
  10.     execution is resumed as a return from SetJump, with SetJump
  11.     returning the 'return' value passed to LongJump, which, for
  12.     obvious reasons, must not be 0.
  13.  
  14.     When LongJump is invoked, the procedure that did the corresponding
  15.     SetJump must still be active !!!
  16.  
  17.     Example:
  18.  
  19.         PROCEDURE main;
  20.         ...
  21.             IF SetJump( env ) = 0 THEN
  22.                 Parse
  23.             ELSE
  24.                 WriteString("error in Parse")
  25.             END;
  26.         ...
  27.         PROCEDURE Parse;
  28.         ...
  29.             IF errorcond THEN LongJump( env, 1 ) END;
  30.  
  31.     The procedure main calls SetJump to save the current execution
  32.     environment in env. SetJump returns 0, and Parse is called.
  33.     If Parse detects an error, it calls LongJump with a return value of
  34.     1. The main procedure is resumed at the point of return from SetJump,
  35.     the IF fails and the string is written out.
  36. *)
  37.  
  38. TYPE
  39.     JumpBuffer = RECORD
  40.         savPC, savCS,
  41.         savSP,
  42.         savBP :CARDINAL;
  43.     END;
  44.  
  45. PROCEDURE SetJump( VAR mark :JumpBuffer ) :CARDINAL;
  46. (*
  47.     save the current execution environment in mark, return 0
  48. *)
  49.  
  50. PROCEDURE LongJump( VAR mark :JumpBuffer; return :CARDINAL );
  51. (*
  52.     restore the environment saved in mark, return from SetJump
  53.     with the value return.
  54. *)
  55.  
  56. END LongJump.